﻿using Microsoft.AspNetCore.Mvc;
using read_write_separation.Entities;
using SqlSugar;

namespace read_write_separation.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CallController(ISqlSugarClient db) : ControllerBase
    {
        private readonly ISqlSugarClient db = db;

        [HttpGet]
        public IActionResult SlaveGet()
        {
            var users = db.Queryable<User>().ToList();
            return Ok(users);
        }

        [HttpGet]
        public IActionResult MasterGet()
        {
            var users = db.MasterQueryable<User>().ToList();
            return Ok(users);
        }

        [HttpGet]
        public IActionResult MasterPost(string name)
        {
            db.Ado.ExecuteCommand($"UPDATE User SET name = '{name}'");
            return Ok("成功");
        }
    }
}
